xend: Fix duplicate random MAC generation.
authorkfraser@localhost.localdomain <kfraser@localhost.localdomain>
Mon, 11 Jun 2007 09:22:32 +0000 (10:22 +0100)
committerkfraser@localhost.localdomain <kfraser@localhost.localdomain>
Mon, 11 Jun 2007 09:22:32 +0000 (10:22 +0100)
Ensure that HVMImageHandler and NetifController see the same random
MAC address.

Signed-off-by: David Edmondson <dme@sun.com>
tools/python/xen/xend/XendConfig.py
tools/python/xen/xend/image.py
tools/python/xen/xend/server/netif.py

index 5ca32337094e54a711d0714749528f8b8215115f..b24a94d348dbff48d570eab56e9f7ff9eb8d3357 100644 (file)
@@ -27,6 +27,7 @@ from xen.xend.XendError import VmError
 from xen.xend.XendDevices import XendDevices
 from xen.xend.PrettyPrint import prettyprintstring
 from xen.xend.XendConstants import DOM_STATE_HALTED
+from xen.xend.server.netif import randomMAC
 
 log = logging.getLogger("xend.XendConfig")
 log.setLevel(logging.WARN)
@@ -993,6 +994,10 @@ class XendConfig(dict):
                 else:
                     dev_info['driver'] = 'paravirtualised'
 
+            if dev_type == 'vif':
+                if not dev_info.get('mac'):
+                    dev_info['mac'] = randomMAC()
+
             # create uuid if it doesn't exist
             dev_uuid = dev_info.get('uuid', None)
             if not dev_uuid:
@@ -1051,8 +1056,9 @@ class XendConfig(dict):
             dev_info = {}
             dev_uuid = ''
             if dev_type == 'vif':
-                if cfg_xenapi.get('MAC'): # don't add if blank
-                    dev_info['mac'] = cfg_xenapi.get('MAC')
+                dev_info['mac'] = cfg_xenapi.get('MAC')
+                if not dev_info['mac']:
+                    dev_info['mac'] = randomMAC()
                 # vifname is the name on the guest, not dom0
                 # TODO: we don't have the ability to find that out or
                 #       change it from dom0
index 527a13093b486ca2fa44e88828bd5f32e33b0303..c578057117a97cd436d8bc9f1d56b8d531b5eefa 100644 (file)
@@ -27,7 +27,6 @@ from xen.xend.XendConstants import REVERSE_DOMAIN_SHUTDOWN_REASONS
 from xen.xend.XendError import VmError, XendError, HVMRequired
 from xen.xend.XendLogging import log
 from xen.xend.XendOptions import instance as xenopts
-from xen.xend.server.netif import randomMAC
 from xen.xend.xenstore.xswatch import xswatch
 from xen.xend import arch
 
@@ -351,7 +350,7 @@ class HVMImageHandler(ImageHandler):
             nics += 1
             mac = devinfo.get('mac')
             if mac is None:
-                mac = randomMAC()
+                raise VmError("MAC address not specified or generated.")
             bridge = devinfo.get('bridge', 'xenbr0')
             model = devinfo.get('model', 'rtl8139')
             ret.append("-net")
index 6211e35ada75b0901e88c98e3dee904f7f9759d0..3c70b389be0b227af1aaa65d01379878d4296a6d 100644 (file)
@@ -112,7 +112,7 @@ class NetifController(DevController):
             typ = xoptions.netback_type
 
         if not mac:
-            mac = randomMAC()
+            raise VmError("MAC address not specified or generated.")
 
         devid = self.allocateDeviceID()